<?php
/*
 *      autartijobs.php
 *      
 *      Copyright 2010 Michael Gyen <GyenMic@autartica.be>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.model' );


class AutartiJobsModelAutartiJobs extends JModel
{
	/**
	 * Jobs data array
	 *
	 * @var array
	 */
	var $_data;
	
	/**
  	 * Items total
  	 * @var integer
  	*/
 	 var $_total = null;
	 
	  /**
   	* Pagination object
  	 * @var object
   	*/
  	var $_pagination = null;
  	
  	/**
  	 * Order
  	 * @var array
  	 */
  	var $_order  = array();
  	
  	function __construct()
  	{
        parent::__construct();
 
        global $mainframe, $option;
 
        // Get pagination request variables
        $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
        $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
 
        // In case limit has been changed, adjust it
        $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
 
        $this->setState('limit', $limit);
        $this->setState('limitstart', $limitstart);
        
        $this->_order[] = JRequest::getVar('filter_order', 'id', 'POST', 'cmd');
		$this->_order[] = JRequest::getVar('filter_order_Dir', 'desc', 'POST', 'word');
  	}
  
  	

	/**
	 * Returns the query
	 * @return string The query to be used to retrieve the rows from the database
	 */
	function _buildQuery()
	{
		$query = ' SELECT * '
			. ' FROM #__autartijob'
		;
		$orderby=$this->_buildContentOrderBy();
	
		return $query.$orderby;
	}

	/**
	 * Retrieves the data
	 * @return array Array of objects containing the data from the database
	 */
	function getData()
	{
		// Lets load the data if it doesn't already exist
		if (empty( $this->_data ))
		{
			$query = $this->_buildQuery();
			$this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit')); 
			
		}

		return $this->_data;
	}
	function getTotal()
  	{
        // Load the content if it doesn't already exist
        if (empty($this->_total)) {
            $query = $this->_buildQuery();
            $this->_total = $this->_getListCount($query);    
        }
        return $this->_total;
  	}
  	
	function getPagination()
  	{
        // Load the content if it doesn't already exist
        if (empty($this->_pagination)) {
            jimport('joomla.html.pagination');
            $this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
        }
        return $this->_pagination;
  	}
	
  	function _buildContentOrderBy()
	{
        return ' ORDER BY '.$this->_order[0].' '.$this->_order[1].' ';
		
	}
	function getOrder() {
 		return $this->_order;
	}
  

}
?>

